/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.verolux.soft.debaraz.utils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

/**
 *
 * @author ut1e8p
 */
public class UploadUtils {

    /**
     *
     * @param multipartFile
     * @param outputPath
     * @throws FileNotFoundException
     * @throws IOException
     */
    public static void writeStream(CommonsMultipartFile multipartFile, String outputPath) throws IOException {
        File f = new File(outputPath);
        FileUtils.copyInputStreamToFile(multipartFile.getInputStream(), f);
    }

    /**
     *
     * @param inputFileNameWithExtension
     * @param outputFileRootNameWithoutExtension
     * @param outputDir
     * @return
     */
    public static String buildOutputFilePath(String inputFileNameWithExtension, String outputFileRootNameWithoutExtension, String outputDir) {
        String ext = FilenameUtils.getExtension(inputFileNameWithExtension);
        String name = outputDir + "/" + outputFileRootNameWithoutExtension + "." + ext;
        return name;
    }
}
